﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
//using System.IO.Compression;
using System.Linq;
using System.Windows;
using Ionic.Zip;
using WK.Libraries.BetterFolderBrowserNS;
using System.Windows.Forms;
using System.Text;
using Newtonsoft.Json;

//Shared lib should be referenced by link.
namespace KaroglanSharedLib
{
    public static class VersionFetcher
    {

    }

    public class VersionList
    {
        public static string versionListPath = @"VersionList.json";
        public List<string> versions { get; set; }
        public Dictionary<string, Version> versionDate { get; set; }

        public VersionList()
        {
            versions = new List<string>();
            versionDate = new Dictionary<string, Version>();
        }

        public void Add(Version version)
        {
            versions.Add(version.FromVersion);
            versionDate[version.FromVersion] = version;
            Save();
        }

        public static VersionList Instance
        {
            get
            {
                if (_versionList == null)
                {
                    Load();
                }
                return _versionList;
            }
        }

        private static VersionList _versionList;

        public static void Load()
        {
            if (!File.Exists(versionListPath))
            {
                _versionList = new VersionList();
                Save();
            }
            string rawData = File.ReadAllText(versionListPath);
            _versionList = JsonConvert.DeserializeObject<VersionList>(rawData);
        }

        public static void Save()
        {
            var rawData = JsonConvert.SerializeObject(Instance);
            File.WriteAllText(versionListPath, rawData);
        }
    }

    public class Version
    {
        public string FromVersion;
        public string ToVersion;
        public string packUrl;
        public string packSize;
        public string packCount;
    }
}
